






module.exports=function(){







    this.scx=device.width/1080
    this.scy=device.height/1920

    this.获取指定点颜色=function(x,y){
        var img = captureScreen()
        var color=images.pixel(img, x*this.scx, y*this.scy)
        return colors.toString(color)
    }
    
    this.页面图色特征=function(){
        var img = captureScreen()
        var 图色特征=""
        for(i=0;i<6;i++){
            for(j=0;j<5;j++){
                var x=300+100*i
                var y=800+100*j
                var color=images.pixel(img, x*this.scx, y*this.scy)
                图色特征=图色特征+colors.toString(color)
            }
        }
        return 图色特征
    }
    
    this.单点比色=function(x,y,color,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var 返回值=images.detectsColor(img, this.BGR转RGB(color), x*this.scx, y*this.scy, th, "diff")
        return 返回值
    }
    
    this.多点比色=function(colors,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var 数组1=colors.split(",")
        for(i=0;i<数组1.length;i++){
            var 数组2=数组1[i].split("|")
            var x=Number(数组2[0])
            var y=Number(数组2[1])
            var color=数组2[2]
            if(images.detectsColor(img, this.BGR转RGB(color), x*this.scx, y*this.scy, th, "diff")==false){
                return false
            }
        }
        return true
    }


    this.单点找色=function(x1,y1,x2,y2,color,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var point = images.findColor(img, this.BGR转RGB(color), {
            region: [x1*this.scx, y1*this.scy, x2*this.scx-x1*this.scx, y2*this.scy-y1*this.scy],
            threshold: th
        })
        if(point!=null){
            return true
        }else{
            return false  
        }  
    }
    
    
    this.多点找色=function(x1,y1,x2,y2,first_color,offset_color,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var point = images.findMultiColors(img, this.BGR转RGB(first_color), this.offset_color字符串转数组(offset_color), {
            region: [x1*this.scx, y1*this.scy, x2*this.scx-x1*this.scx, y2*this.scy-y1*this.scy],
            threshold: th
        }) 
        if(point!=null){
            return true
        }else{
            return false  
        }
    }

    this.单点找色_点击=function(x1,y1,x2,y2,color,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var point = images.findColor(img, this.BGR转RGB(color), {
            region: [x1*this.scx, y1*this.scy, x2*this.scx-x1*this.scx, y2*this.scy-y1*this.scy],
            threshold: th
        })
        if(point!=null){
            if(device.sdkInt<24){ 
                shell("input tap "+point.x+" "+point.y,true)  
            }else{
                click(point.x,point.y)
            }
            return true
        }else{
            return false  
        }  
    }
    
    
    this.多点找色_点击=function(x1,y1,x2,y2,first_color,offset_color,sim){
        var img = captureScreen()
        var th=Math.round(255-255*sim)
        var point = images.findMultiColors(img, this.BGR转RGB(first_color), this.offset_color字符串转数组(offset_color), {
            region: [x1*this.scx, y1*this.scy, x2*this.scx-x1*this.scx, y2*this.scy-y1*this.scy],
            threshold: th
        }) 
        if(point!=null){
            if(device.sdkInt<24){ 
                shell("input tap "+point.x+" "+point.y,true)  
            }else{
                click(point.x,point.y)
            }
            return true
        }else{
            return false  
        }
    }

    this.BGR转RGB=function(bgr){
        var b=bgr.slice(0,2)
        var g=bgr.slice(2,4)
        var r=bgr.slice(4,6)
        var rgb="#"+r+g+b
        return rgb
    }

    this.offset_color字符串转数组=function(offset_color字符串){
        var 返回数组=new Array()
        var 数组1=offset_color字符串.split(",")
        for(i=0;i<数组1.length;i++){
            var 数组2=数组1[i].split("|")
            var 数组3=[Number(数组2[0])*this.scx,Number(数组2[1])*this.scy,this.BGR转RGB(数组2[2])]
            返回数组.push(数组3)
        }
        return 返回数组
    }

}

